#include <iostream>
#include "Adder.h"

AdderImp::AdderImp(void)
#ifdef DEBUG_EVPROC
: EventProcessorImp(true, "Adder") // comment to remove debug
#endif
{
  sum=0;
  
  // register the messages
  RegisterMessageProcessor(DieMessage::type, &Die, 0 /* highest priority */);
  RegisterMessageProcessor(TestGeneratorMessage::type, &AddMe, 1 /*priority*/);
}

// AddMe handler definition
MESSAGE_HANDLER_DEFINITION_BEGIN(AdderImp, AddMe, TestGeneratorMessage)
  // add the numer to the sum
  evProc.sum+=msg.number;
  
  // send the reply back
  TestNextMessage_Factory(msg.sender);
MESSAGE_HANDLER_DEFINITION_END

// Die handler definition
MESSAGE_HANDLER_DEFINITION_BEGIN(AdderImp, Die, DieMessage)

  cout<<"The total is: "<< evProc.sum << endl;
  // call the underlying die message to still die
  evProc.EventProcessorImp::processDieMessage(evProc,msg);

MESSAGE_HANDLER_DEFINITION_END

